//
//  CXDestinationDetailHeadCollectionReusableView.m
//  Travel
//
//  Created by dllo on 15/11/30.
//  Copyright © 2015年 doll. All rights reserved.
//

#import "CXDestinationDetailHeadCollectionReusableView.h"
#import "CXDestinationModel.h"
#import "Masonry.h"

@interface CXDestinationDetailHeadCollectionReusableView ()

@property (nonatomic, strong) NSMutableArray *dataArr;

//分割线3
@property (nonatomic, strong) UILabel *label_MBR;

@property (nonatomic, strong) UILabel *label_place;
@property (nonatomic, strong) UILabel *label_place_left;
@property (nonatomic, strong) UILabel *label_place_right;

@property (nonatomic, strong) UILabel *label_place_left_left;
@property (nonatomic, strong) UILabel *label_place_right_right;

//btn1
@property (nonatomic, strong) UIButton *btn1;
@property (nonatomic, strong) UIImageView *img1;
@property (nonatomic, strong) UILabel *label1;

//分割线1
@property (nonatomic, strong) UILabel *label1_2;

@property (nonatomic, strong) UIButton *btn2;
@property (nonatomic, strong) UIImageView *img2;
@property (nonatomic, strong) UILabel *label2;

//分割线2
@property (nonatomic, strong) UILabel *label2_3;

@property (nonatomic, strong) UIButton *btn3;
@property (nonatomic, strong) UIImageView *img3;
@property (nonatomic, strong) UILabel *label3;

//分割线3
@property (nonatomic, strong) UILabel *label3_4;

@property (nonatomic, strong) UIButton *btn4;
@property (nonatomic, strong) UIImageView *img4;
@property (nonatomic, strong) UILabel *label4;


@end


@implementation CXDestinationDetailHeadCollectionReusableView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createView];
        
    }
    return self;
}

- (void)createView
{
    self.btn1 = [UIButton buttonWithType:UIButtonTypeSystem];
    //self.btn1.backgroundColor = [UIColor redColor];
    [self.btn1 addTarget:self action:@selector(missAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.btn1];
    
    self.img1 = [[UIImageView alloc] init];
    self.img1.image = [UIImage imageNamed:@"good"];
    //self.img1.backgroundColor = [UIColor yellowColor];
    [self.btn1 addSubview:self.img1];
    
    self.label1 = [[UILabel alloc] init];
    //self.label1.backgroundColor = [UIColor blueColor];
    self.label1.textAlignment = NSTextAlignmentCenter;
    self.label1.text = @"精品游记";
    [self.btn1 addSubview:self.label1];
    
    
    self.label_MBR = [[UILabel alloc] init];
    self.label_MBR.backgroundColor = [UIColor colorWithRed:0.74 green:0.72 blue:0.59 alpha:1];
    [self addSubview:self.label_MBR];
    
    self.label_place = [[UILabel alloc] init];
    //self.label_place.backgroundColor = [UIColor redColor];
    self.label_place.textAlignment = NSTextAlignmentCenter;
    self.label_place.font = [UIFont systemFontOfSize:20];
    //self.label_place.font = [UIFont systemFontOfSize:20];
    self.label_place.text = @"热门地点";
    [self addSubview:self.label_place];
    
    self.label_place_left = [[UILabel alloc] init];
    self.label_place_left.backgroundColor = [UIColor colorWithRed:0.74 green:0.72 blue:0.59 alpha:1];
    self.label_place_left.layer.cornerRadius = 3;
    self.label_place_left.clipsToBounds = YES;
    [self addSubview:self.label_place_left];
    
    self.label_place_right = [[UILabel alloc] init];
    self.label_place_right.backgroundColor = [UIColor colorWithRed:0.74 green:0.72 blue:0.59 alpha:1];
    self.label_place_right.layer.cornerRadius = 3;
    self.label_place_right.clipsToBounds = YES;
    [self addSubview:self.label_place_right];
    
    self.label_place_left_left = [[UILabel alloc] init];
    self.label_place_left_left.backgroundColor = [UIColor colorWithRed:0.74 green:0.72 blue:0.59 alpha:1];
    self.label_place_left_left.layer.cornerRadius = 3;
    self.label_place_left_left.clipsToBounds = YES;
    [self addSubview:self.label_place_left_left];
    
    self.label_place_right_right = [[UILabel alloc] init];
    self.label_place_right_right.backgroundColor = [UIColor colorWithRed:0.74 green:0.72 blue:0.59 alpha:1];
    self.label_place_right_right.layer.cornerRadius = 3;
    self.label_place_right_right.clipsToBounds = YES;
    [self addSubview:self.label_place_right_right];
    
}

- (void)missAction
{
    self.missGood(self.model_destination);
}

- (void)Action2
{
    self.miss(self.dataArr[0][@"url"]);
}

- (void)Action3
{
    self.miss(self.dataArr[1][@"url"]);
}

- (void)Action4
{
    self.miss(self.dataArr[2][@"url"]);
}


- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    
    [self.btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(15);
        make.top.mas_equalTo(self).offset(15);
        //make.right.mas_equalTo(self.label_MB.mas_left).offset(-10);
        make.width.mas_equalTo(@((WIDTH - 90) / 4));
        make.height.mas_equalTo(@((WIDTH - 90) / 4 + 10));
    }];
    
    [self.img1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.btn1).insets(UIEdgeInsetsMake(0, 10, 30, 10));
    }];
    [self.label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.img1.mas_bottom);
        make.left.mas_equalTo(self.btn1);
        make.right.mas_equalTo(self.btn1);
        make.bottom.mas_equalTo(self.btn1);
    }];
    

    [self.label_place mas_makeConstraints:^(MASConstraintMaker *make) {
        //make.top.mas_equalTo(self.label_MBR).offset(10);
        make.bottom.mas_equalTo(self).offset(-10);
        //make.left.mas_equalTo(self).offset(80);
        //make.right.mas_equalTo(self).offset(-80);
        make.centerX.mas_equalTo(self);
        make.width.mas_equalTo(@100);
        make.height.mas_equalTo(@30);
    }];
    //self.label_place.backgroundColor = [UIColor redColor];
    
    [self.label_place_left mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(6, 6));
        make.centerY.mas_equalTo(self.label_place);
        make.right.mas_equalTo(self.label_place.mas_left).offset(-10);
    }];
    
    [self.label_place_right mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(6, 6));
        make.centerY.mas_equalTo(self.label_place);
        make.left.mas_equalTo(self.label_place.mas_right).offset(10);
    }];
    
    [self.label_place_left_left mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(20);
        make.height.mas_equalTo(@2);
        make.right.mas_equalTo(self.label_place_left.mas_left).offset(-10);
        make.centerY.mas_equalTo(self.label_place);
      
    }];
    
    [self.label_place_right_right mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(@2);
        make.centerY.mas_equalTo(self.label_place);
        make.left.mas_equalTo(self.label_place_right.mas_right).offset(10);
        make.right.mas_equalTo(self).offset(-20);
    }];
    
    [self.label_MBR mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(10);
        //make.top.mas_equalTo(self.btn_miss.mas_bottom).offset(20);
        make.bottom.mas_equalTo(self).offset(-50);
        make.right.mas_equalTo(self).offset(-10);
        make.height.mas_equalTo(@2);
    }];
    
    
}

- (void)setArr_tools:(NSArray *)arr_tools
{
    self.dataArr = [NSMutableArray array];
    for (NSDictionary *dic in arr_tools) {
        if (![dic[@"url"] isEqualToString:@""]) {
            [self.dataArr addObject:dic];
        }
    }
    
    if (self.dataArr.count == 1) {
        [self yushu1:self.dataArr[0][@"type"] ];
    }else if(self.dataArr.count == 2){
        [self yushu1:self.dataArr[0][@"type"]];
        [self yushu2:self.dataArr[1][@"type"]];
    }else if(self.dataArr.count == 3){
        [self yushu1:self.dataArr[0][@"type"]];
        [self yushu2:self.dataArr[1][@"type"]];
        [self yushu3:self.dataArr[2][@"type"]];
    }else{
        
    }
    
}

- (NSString *)payName:(NSNumber *)number
{
    if ([number  isEqual: @7]) {
        return  @"不可错过";
    }else if ([number  isEqual: @6]){
        return  @"推荐路线";
    }else if ([number  isEqual: @5]){
        return  @"特价产品";
    }else if ([number  isEqual: @4]){
        return  @"主题榜单";
    }else if ([number  isEqual: @1]){
        return  @"实用须知";
    }else{
        return nil;
    }
}

- (NSString *)payImage:(NSNumber *)number
{
    if ([number  isEqual: @7]) {
        return  @"miss";
    }else if ([number  isEqual: @6]){
        return  @"recommend";
    }else if ([number  isEqual: @5]){
        return  @"specialPrice";
    }else if ([number  isEqual: @4]){
        return  @"pre";
    }else if ([number  isEqual: @1]){
        return  @"tip";
    }else{
        return nil;
    }
}


- (void)yushu1:(NSNumber *)numb
{
    self.label1_2 = [[UILabel alloc] init];
    self.label1_2.backgroundColor = [UIColor colorWithRed:0.74 green:0.72 blue:0.59 alpha:1];
    [self addSubview:self.label1_2];
    
    self.btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
    //self.btn2.backgroundColor = [UIColor yellowColor];
    [self.btn2 addTarget:self action:@selector(Action2) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.btn2];
    
    self.img2 = [[UIImageView alloc] init];
    self.img2.image = [UIImage imageNamed:[self payImage:numb]];
    //self.img2.backgroundColor = [UIColor redColor];
    [self.btn2 addSubview:self.img2];
    
    self.label2 = [[UILabel alloc] init];
    self.label2.textAlignment = NSTextAlignmentCenter;
    self.label2.text = [self payName:numb];
    [self.btn2 addSubview:self.label2];
    
    
    [self.label1_2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.btn1.mas_right).offset(10);
        make.top.mas_equalTo(self).offset(20);
        make.width.mas_equalTo(@2);
        make.height.mas_equalTo(@((WIDTH - 90) / 4 + 10));
    }];
    
    [self.btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.label1_2.mas_right).offset(10);
        make.top.mas_equalTo(self).offset(15);
        
        make.width.mas_equalTo(@((WIDTH - 90) / 4));
        make.height.mas_equalTo(@((WIDTH - 90) / 4 + 10));
    }];
    
    [self.img2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.btn2).insets(UIEdgeInsetsMake(0, 10, 30, 10));
    }];
    [self.label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.img2.mas_bottom);
        make.left.mas_equalTo(self.btn2);
        make.right.mas_equalTo(self.btn2);
        make.bottom.mas_equalTo(self.btn2);
    }];
    
}

- (void)yushu2:(NSNumber *)numb
{
    self.label2_3 = [[UILabel alloc] init];
    self.label2_3.backgroundColor = [UIColor colorWithRed:0.74 green:0.72 blue:0.59 alpha:1];
    [self addSubview:self.label2_3];
    
    self.btn3 = [UIButton buttonWithType:UIButtonTypeSystem];
    //self.btn3.backgroundColor = [UIColor blueColor];
    [self.btn3 addTarget:self action:@selector(Action3) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.btn3];
    
    self.img3 = [[UIImageView alloc] init];
    self.img3.image = [UIImage imageNamed:[self payImage:numb]];
    //self.img3.backgroundColor = [UIColor redColor];
    [self.btn3 addSubview:self.img3];
    
    self.label3 = [[UILabel alloc] init];
    self.label3.textAlignment = NSTextAlignmentCenter;
    self.label3.text = [self payName:numb];
    [self.btn3 addSubview:self.label3];
    
    [self.label2_3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.btn2.mas_right).offset(10);
        make.top.mas_equalTo(self).offset(20);
        //make.right.mas_equalTo(self.btn_recommend.mas_left).offset(-10);
        make.width.mas_equalTo(@2);
        make.height.mas_equalTo(@((WIDTH - 90) / 4 + 10));
    }];
    
    [self.btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.label2_3.mas_right).offset(10);
        make.top.mas_equalTo(self).offset(15);
        //make.right.mas_equalTo(self.label_last).offset(-10);
        make.width.mas_equalTo(@((WIDTH - 90) / 4));
        make.height.mas_equalTo(@((WIDTH - 90) / 4 + 10));
    }];
    [self.img3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.btn3).insets(UIEdgeInsetsMake(0, 10, 30, 10));
    }];
    [self.label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.img3.mas_bottom);
        make.left.mas_equalTo(self.btn3);
        make.right.mas_equalTo(self.btn3);
        make.bottom.mas_equalTo(self.btn3);
    }];
    
}

- (void)yushu3:(NSNumber *)numb
{
    
    self.label3_4 = [[UILabel alloc] init];
    self.label3_4.backgroundColor = [UIColor colorWithRed:0.74 green:0.72 blue:0.59 alpha:1];
    [self addSubview:self.label3_4];
    
    
    self.btn4 = [UIButton buttonWithType:UIButtonTypeSystem];
    //self.btn4.backgroundColor = [UIColor blueColor];
    [self.btn4 addTarget:self action:@selector(Action4) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.btn4];
    
    self.img4 = [[UIImageView alloc] init];
    self.img4.image = [UIImage imageNamed:[self payImage:numb]];
    //self.img4.backgroundColor = [UIColor redColor];
    [self.btn4 addSubview:self.img4];
    
    self.label4 = [[UILabel alloc] init];
    self.label4.textAlignment = NSTextAlignmentCenter;
    self.label4.text = [self payName:numb];
    [self.btn4 addSubview:self.label4];
    
    
    [self.label3_4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.btn3.mas_right).offset(10);
        make.top.mas_equalTo(self).offset(20);
        //make.right.mas_equalTo(self.btn_last.mas_left).offset(-10);
        make.width.mas_equalTo(@2);
        make.height.mas_equalTo(@((WIDTH - 90) / 4 + 10));
        
    }];
    
    [self.btn4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.label3_4.mas_right).offset(10);
        make.top.mas_equalTo(self).offset(15);
        //make.right.mas_equalTo(self).offset(-15);
        make.width.mas_equalTo(@((WIDTH - 90) / 4));
        make.height.mas_equalTo(@((WIDTH - 90) / 4 + 10));
    }];
    [self.img4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.btn4).insets(UIEdgeInsetsMake(0, 10, 30, 10));
    }];
    [self.label4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.img4.mas_bottom);
        make.left.mas_equalTo(self.btn4);
        make.right.mas_equalTo(self.btn4);
        make.bottom.mas_equalTo(self.btn4);
    }];
    
    
}



@end
